package model

import (
	"github.com/go-redis/redis/v8"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var db *gorm.DB
var st *redis.Client

// 购物车表
type Cart struct {
	gorm.Model
	UserId  int     `gorm:"type:int;not null"`
	GoodsId int     `gorm:"type:int;not null"`
	Number  int     `gorm:"type:int;not null"`
	Price   float64 `gorm:"type:decimal(10,2);not null"`
	Status  int     `gorm:"type:int;not null"`
}

// 订单表
type Order struct {
	gorm.Model
	UserId  int     `gorm:"type:int;not null"`
	GoodsId int     `gorm:"type:int;not null"`
	Number  int     `gorm:"type:int;not null"`
	Price   float64 `gorm:"type:decimal(10,2);not null"`
	Status  int     `gorm:"type:int;not null"`
}

// 订单商品详情表
type OrderGoods struct {
	gorm.Model
	OrderId int `gorm:"type:int;not null"`
	GoodsId int `gorm:"type:int;not null"`
	Number  int `gorm:"type:int;not null"`
}

func init() {
	dns := "root:root@tcp(127.0.0.1:3305)/daytest?charset=utf8mb4&parseTime=True&loc=Local"
	db, _ = gorm.Open(mysql.Open(dns), &gorm.Config{})
	db.AutoMigrate(new(User))
	st = redis.NewClient(&redis.Options{
		Addr:     "127.0.0.1:6379",
		Password: "",
		DB:       0,
	})
}
